import os
from os import listdir


# In[11]:


def suffixList(filepath):

    music_names = listdir(filepath) #获取文件夹内文件的名字

    suffix = []
    for name in music_names:
        suff = os.path.splitext(name)[-1] #将文件名和扩展名分开，并返回文件名
        if suff in suffix:
            pass
        else:
            suffix.append(suff)
    try:
        suffix.remove('')
        suffix.remove('.ncm')
        suffix.remove('.jpg')
    except:
        pass
    return suffix

def nameList(music_dir,suffix_list):
    music_all_list = listdir(music_dir) #get names of all music in Music_dir
    music_list = []
    for name in music_all_list:
        suff = os.path.splitext(name)[-1] # get suffix of each name
        if suff in suffix_list:
            music_list.append(name)
        else:
            pass
    return music_list
def getlist(filepath):
    suffix = suffixList(filepath)

    List = nameList(filepath, suffix)
    # for i in range(len(List)):
    #   print(List[i])
    return List